<?php

namespace App\Nova;

use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Image;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Textarea;
use Laravel\Nova\Fields\Trix;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Panel;

class Post extends Resource
{
    public static string $model = \App\Models\Post::class;

    public static $title = 'title';

    public static $search = [
        'title',
    ];

    public static function label(): string
    {
        return '文章';
    }

    public function fields(NovaRequest $request): array
    {
        return [
            ID::make()->sortable(),

            Text::make('标题', 'title')->rules('required'),

            Image::make('缩略图', 'picture')->prunable(),

            Textarea::make('简介', 'description')->alwaysShow()->maxlength(255, true),

            Trix::make('内容', 'content')->withFiles('public'),

            Boolean::make('显示', 'show')->default(true),

            new Panel('SEO', new SeoFields),

            DateTime::make('生成时间', 'created_at')->onlyOnDetail(),
            DateTime::make('更新时间', 'updated_at')->exceptOnForms(),
        ];
    }
}
